package son.hut.vn;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {
	private ListView lvStudent;
	private String[] arrayStudent = {"Hoa","Thang","Thanh","Loc","Tuan","Nam"};
	private ArrayAdapter<String> adapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		lvStudent = (ListView)findViewById(R.id.lvStudent);
		adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, arrayStudent);
		lvStudent.setAdapter(adapter);
		
		//doi voi listview thuong quan li 2 su kien click va long click
		lvStudent.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,	long id) {
				// duoc goi bat ki khi nao co su kien click vao item cua listview;
				String contentItem= parent.getItemAtPosition(position).toString();
				Toast.makeText(MainActivity.this, contentItem , Toast.LENGTH_LONG).show();
			}
		});
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
